import { http } from "@/utils/http";
export function parseStrEmpty(str) {
  if (!str || str == "undefined" || str == "null") {
    return "";
  }
  return str;
}
// 查询角色列表
export function listRole(query) {
  return http.request("get", "/system/role/list", { params: query });
}

// 查询角色详细
export function getRole(roleId) {
  return http.request("get", "/system/role/" + parseStrEmpty(roleId));
}

// 新增角色
export function addRole(data) {
  return http.request("post", "/system/role", { data });
}

// 修改角色
export function updateRole(data) {
  return http.request("put", "/system/role", { data });
}

// 角色状态修改
export function changeRoleStatus(roleId, status) {
  const data = {
    roleId,
    status
  };
  return http.request("put", "/system/role/changeStatus", { data });
}

// 删除角色
export function delRole(roleId) {
  return http.request("delete", "/system/role/" + roleId);
}

// 查询角色已授权用户列表
export function allocatedUserList(query) {
  return http.request("get", "/system/role/authUser/allocatedList",{ params: query });
}

// 查询角色未授权用户列表
export function unallocatedUserList(query) {
  return http.request("get", "/system/role/authUser/unallocatedList", { params: query });
}

// 取消用户授权角色
export function authUserCancel(data) {
  return http.request("put", "/system/role/authUser/cancel", { data });
}

// 批量取消用户授权角色
export function authUserCancelAll(data) {
  return http.request("put", "/system/role/authUser/cancelAll", { data });
}

// 授权用户选择
export function authUserSelectAll(data) {
  return http.request("put", "/system/role/authUser/selectAll", { data });
}
